﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Permision.DAL;
using Tools;

namespace Permision.BLL
{
    /// <summary>
    /// Summary description for ActionsRolesBase
    /// </summary>
    public class Per_ActionsRolesManagerBase
    {
        public Per_ActionsRolesManagerBase()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public void InsertUpdate(Per_ActionsRolesEntity item)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", item.Id));
            ls.Add(new SqlParameter("@RoleName", item.RoleName));
            ls.Add(new SqlParameter("@ActionId", item.ActionId));
            ls.Add(new SqlParameter("@ModuleId", item.ModuleId));
            ls.Add(new SqlParameter("@Permissions", item.Permissions));
            SqlParameter[] sqlparam = ls.ToArray();
            Tools.SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_InsertUpdatePer_ActionsRoles", sqlparam);
        }
        public void InsertUpdate(int Id, string RoleName, string ActionId, string ModuleId, string Permissions)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            ls.Add(new SqlParameter("@RoleName", RoleName));
            ls.Add(new SqlParameter("@ActionId", ActionId));
            ls.Add(new SqlParameter("@ModuleId", ModuleId));
            ls.Add(new SqlParameter("@Permissions", Permissions));
            SqlParameter[] sqlparam = ls.ToArray();
            Tools.SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_InsertUpdatePer_ActionsRole", sqlparam);
        }
        public void Delete(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            Tools.SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_DeletePer_ActionsRoles", sqlparam);
        }
        public Per_ActionsRolesEntity GetPer_ActionsRolesEntity(DataRow dr)
        {
            Per_ActionsRolesEntity item = new Per_ActionsRolesEntity();            
            item.Id = dr["Id"].ToInt();              
            item.RoleName = dr["RoleName"].ToString();              
            item.ActionId = dr["ActionId"].ToString();              
            item.ModuleId = dr["ModuleId"].ToString();              
            item.Permissions = dr["Permissions"].ToString();              
            return item;
        }
        
        public DataTable SelectOneRDT(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            return Tools.SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_SelectPer_ActionsRoles", sqlparam);
        }
        public Per_ActionsRolesEntity SelectOne(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = Tools.SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_SelectPer_ActionsRoles", sqlparam);
            if(dt!=null && dt.Rows.Count>0)
                return GetPer_ActionsRolesEntity(dt.Rows[0]);
            return null;
        }
        public DataTable SelectAllRDT()
        {
            return Tools.SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_SelectPer_ActionsRolesAll", null);
        }
        public List<Per_ActionsRolesEntity> SelectAll()
        {
            List<Per_ActionsRolesEntity> lsresult= new List<Per_ActionsRolesEntity>();
            DataTable dt =  Tools.SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_SelectPer_ActionsRolesAll", null);
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetPer_ActionsRolesEntity(dt.Rows[i]));            
            return lsresult;
        }
        public DataTable SelectByModuleIdRDT(string ModuleId)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@ModuleId ", ModuleId));
            SqlParameter[] sqlparam = ls.ToArray();
            return Tools.SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_SelectPer_ActionsRolesByAndModuleId", sqlparam);
        }      
        public List<Per_ActionsRolesEntity> SelectByModuleId(string ModuleId)
        {
            List<Per_ActionsRolesEntity> lsresult= new List<Per_ActionsRolesEntity>();
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@ModuleId ", ModuleId));
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = Tools.SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_SelectPer_ActionsRolesByAndModuleId", sqlparam);
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetPer_ActionsRolesEntity(dt.Rows[i]));
            return lsresult;
        }      
        public DataTable SelectByActionIdRDT(string ActionId)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@ActionId ", ActionId));
            SqlParameter[] sqlparam = ls.ToArray();
            return Tools.SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_SelectPer_ActionsRolesByAndActionId", sqlparam);
        }      
        public List<Per_ActionsRolesEntity> SelectByActionId(string ActionId)
        {
            List<Per_ActionsRolesEntity> lsresult= new List<Per_ActionsRolesEntity>();
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@ActionId ", ActionId));
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = Tools.SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_SelectPer_ActionsRolesByAndActionId", sqlparam);
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetPer_ActionsRolesEntity(dt.Rows[i]));
            return lsresult;
        }      
    }
}

